package com.pwr.app.characteristics;

import java.text.DecimalFormat;

public class DensityCharacteristics implements BaseCharacteristics {

	@Override
	public double[] computeCharacteristics(boolean[][] image, int sampleRectDim) {
		double[] toReturn = new double[sampleRectDim];
		sampleRectDim = image[0].length / (int) Math.sqrt(sampleRectDim);
		for (int i = 0; i < image[0].length / sampleRectDim; i++)
			for (int l = 0; l < image.length / sampleRectDim; l++) {
				double sum = 0;
				for (int x = 0; x < sampleRectDim; x++)
					for (int y = 0; y < sampleRectDim; y++) {
						if (image[l * sampleRectDim + y][i * sampleRectDim + x])
							sum++;
					}
				if (i * image[0].length / sampleRectDim + l < toReturn.length)
					toReturn[i * image[0].length / sampleRectDim + l] = sum / (double) (sampleRectDim * sampleRectDim);
			}

		return toReturn;
	}
}
